package com.iyoudoock.citymine;

import android.app.Activity;
import android.app.Application;

import com.baidu.mapapi.SDKInitializer;
import com.kvin.toolkit.utils.LogUtils;
import com.kvin.toolkit.utils.ThreadPoolUtils;
import com.sqm.sharelib.SharePlatform;
import com.sqm.sharelib.ShareUtils;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.ArrayList;

/**
 * Created by Kvin on 2017/5/11.
 */
public class BaseApp extends Application {
    private static BaseApp mApp;
    private ArrayList<Activity> acts;

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;

        LogUtils.setDebugMode(true);//default is true;reset to false when publishing

        initBaiduMap();

        ThreadPoolUtils.init(4);

        initShare();

        acts = new ArrayList<>();//manager activity obj
    }

    /**
     * init share
     */
    private void initShare() {
        SharePlatform[] platforms = new SharePlatform[]{
                new SharePlatform(SHARE_MEDIA.WEIXIN, "wx9a58236d67f4b8d9", "a902aaac99125c9af22e0230d29788f3"),
                new SharePlatform(SHARE_MEDIA.QQ, "1104934135", "64ilaOMhFcPjiypA")

        };
        ShareUtils.initSDK(this, "564fe0cce0f55a6e060054ad", platforms);
        ShareUtils.setDebugMode(true);
    }

    /**
     * init baidu map
     */
    private void initBaiduMap() {
        SDKInitializer.initialize(this);
    }

    /**
     * return global context
     */
    public static BaseApp getInstance() {
        return mApp;
    }

    /**
     * add activity
     */
    public void addAct(Activity act) {
        if (act != null) {
            acts.add(act);
        }
    }

    /**
     * exit  system
     */
    public void exit() {
        for (Activity act : acts) {
            if (act != null) act.finish();
        }
    }

}
